<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>proxy基本使用</title>
  </head>
  <body>
    <script>
      let data = {
        name: "zs",
        age: 20
      };

      const proxyData = new Proxy(data, {
        get(target, key, proxyObj) {
          const result = Reflect.get(target, key, proxyObj);
          console.log("get", key, target, proxyObj);
          return target[key]; //
        },
        set(target, key, val, proxyObj) {
          const result = Reflect.set(target, key, val, proxyObj);
          console.log("set", key, val);
          return result;
        },
        deleteProperty(target, key) {
          const result = Reflect.deleteProperty(target, key);
          console.log("delete", key);
          return result;
        }
      });

      proxyData.name = 123;

    </script>
  </body>
</html>
